package main

import "fmt"

/*
* Author: JacksonCoder
* CreateTime: 2025/5/21
 */

// 按字符 rune 遍历

func splice(){
	var s1 = "hello" // 静态字面量
	var s2 = ""
	for i := 0; i < 10; i++{
		s2 += s1 // 动态构造
	}
	fmt.Println(len(s1))
	fmt.Println(len(s2))
}

// 字符串时只读的
func onlyRead(){
	//var s = "hello"
	//s[0] = 'H'
}

// 切割
func cut(){
	var s = "hello GoLang"
	var s2 = s[3:8]
	fmt.Println(s2)
}

// 字节切片和字符串的相互转化
func string2Bytes(){
	var s1 = "hello golang"
	var b = []byte(s1) // 字符串转字节切片
	var s2 = string(b) // 字节切片转字符串
	fmt.Println(b)
	fmt.Println(s2)
}

func main(){
	splice()
	onlyRead()
	cut()
	string2Bytes()
}


